package myTest.web;

import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

@SuppressWarnings("unused")
public class TestPost {

	private static String url = "http://mstore.wo.com.cn/online/online_logOn.action";
	private static String url1 = "http://mstore.wo.com.cn/320fantastic/appDownload_final.jsp?imgUrl=file/90238230/9023823020110530646100/small.png&spname=%E7%99%BE%E5%BA%A6%E5%9C%A8%E7%BA%BF%E7%BD%91%E7%BB%9C%E6%8A%80%E6%9C%AF%EF%BC%88%E5%8C%97%E4%BA%AC%EF%BC%89%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8&cnname=%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE&productId=9023823020110530646100&productIndex=25839&fileSize=2068.61";

	public static void main(String[] args) throws Exception {
		// String data = GetResponseDataByID(
		// url,
		// "telphone=18630066996&passwd=lzl411&preurl=%23&pageFlag="
		// + "1&=%E7%AB%8B%E5%8D%B3%E7%99%BB%E5%BD%95&isLocalPageSubmit=");
		GetResponseDataByID1(url1, "");
		// System.out.println(data);
	}

	public static void GetResponseDataByID1(String url, String postData) {
		String data = null;
		try {
			URL dataUrl = new URL(url);
			HttpURLConnection con = (HttpURLConnection) dataUrl.openConnection();
			con.setRequestMethod("GET");
			con.setRequestProperty("Proxy-Connection", "Keep-Alive");

			// Cookie: __utmmobile=0x29ded66576f12276;
			// JSESSIONID=0F357820106BA48DA6269B8181F66EB5
			con.setRequestProperty("Cookie", "__utmmobile=0x29ded66576f12276; JSESSIONID=88F0E7A15EA35D066EAE095051CDC33E");
			// con.setDoOutput(true);
			con.setDoInput(true);

			// OutputStream os = con.getOutputStream();
			// DataOutputStream dos = new DataOutputStream(os);
			// dos.write(postData.getBytes());
			// dos.flush();
			// dos.close();
			InputStream is;
			is = con.getInputStream();

			BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("fffffffffff.jar"));

			byte[] bs = new byte[1024];
			int len;
			while ((len = is.read(bs)) > 0) {
				out.write(bs, 0, len);
			}
			out.close();
			con.disconnect();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public static String GetResponseDataByID(String url, String postData) {
		String data = null;
		try {
			URL dataUrl = new URL(url);
			HttpURLConnection con = (HttpURLConnection) dataUrl.openConnection();
			con.setRequestMethod("POST");
			con.setRequestProperty("Proxy-Connection", "Keep-Alive");
			con.setDoOutput(true);
			con.setDoInput(true);

			OutputStream os = con.getOutputStream();
			DataOutputStream dos = new DataOutputStream(os);
			dos.write(postData.getBytes());
			dos.flush();
			dos.close();

			InputStream is = con.getInputStream();
			DataInputStream dis = new DataInputStream(is);

			byte d[] = new byte[dis.available()];
			dis.read(d);
			data = new String(d);
			// System.out.println(data);
			con.disconnect();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return data;
	}
}
/*
 * POST /online/online_logOn.action HTTP/1.1 Accept: image/gif, image/x-xbitmap,
 * image/jpeg, image/pjpeg, application/x-shockwave-flash,
 * application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
 * application/x-ms-application, application/x-ms-xbap,
 * application/vnd.ms-xpsdocument, application/xaml+xml, application/QVOD,
 * application/QVOD, * / * Referer:
 * http://mstore.wo.com.cn/320fantastic/login.jsp Accept-Language: zh-cn
 * Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip,
 * deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
 * .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022) Host:
 * mstore.wo.com.cn Content-Length: 113 Connection: Keep-Alive Cache-Control:
 * no-cache Cookie: JSESSIONID=F2254E85781F27C965844AD514B3A698;
 * __utmmobile=0x29ded66576f12276
 * 
 * telphone=18630066996&passwd=lzl411&preurl=%23&pageFlag=1&=%E7%AB%8B%E5%8D%B3%E7
 * %99%BB%E5%BD%95&isLocalPageSubmit=
 */